/* =================================
   GLOBAL
   ================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    min-height: 100vh;

    font-family: Arial, sans-serif;

    background: linear-gradient(
        135deg,
        #667eea,
        #764ba2
    );

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 30px 15px;

    transition: background 0.4s ease;
}


/* =================================
   GAME CONTAINER
   ================================= */

.game-container {
    width: 100%;
    max-width: 500px;

    padding: 30px 25px;

    background: rgba(255, 255, 255, 0.95);

    border-radius: 20px;

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.25);

    text-align: center;

    transition:
        background 0.4s ease,
        color 0.4s ease,
        box-shadow 0.4s ease;
}


/* =================================
   TITLE
   ================================= */

h1 {
    margin-bottom: 25px;

    font-size: 38px;

    color: #333;

    letter-spacing: 2px;
}


/* =================================
   MODE SECTION
   ================================= */

.mode-section {
    display: flex;

    gap: 10px;

    margin-bottom: 20px;
}

.mode-section button {
    flex: 1;

    padding: 12px 10px;

    border: none;

    border-radius: 10px;

    background: #e8e8e8;

    color: #333;

    font-size: 14px;

    font-weight: bold;

    cursor: pointer;

    transition:
        transform 0.2s ease,
        background 0.3s ease,
        color 0.3s ease;
}

.mode-section button:hover {
    transform: translateY(-2px);
}

.mode-section button.active {
    background: #667eea;

    color: white;

    box-shadow:
        0 5px 15px rgba(102, 126, 234, 0.35);
}


/* =================================
   PLAYERS
   ================================= */

.players {
    display: flex;

    gap: 15px;

    margin-bottom: 18px;
}

.player-box {
    flex: 1;

    display: flex;

    flex-direction: column;

    gap: 7px;
}

.player-box label {
    font-size: 14px;

    font-weight: bold;

    color: #555;
}

.player-box input {
    width: 100%;

    padding: 11px;

    border: 2px solid #ddd;

    border-radius: 9px;

    outline: none;

    font-size: 14px;

    text-align: center;

    transition:
        border-color 0.3s ease,
        box-shadow 0.3s ease;
}

.player-box input:focus {
    border-color: #667eea;

    box-shadow:
        0 0 8px rgba(102, 126, 234, 0.25);
}


/* =================================
   DIFFICULTY
   ================================= */

.difficulty-section {
    display: flex;

    justify-content: center;

    align-items: center;

    gap: 10px;

    margin-bottom: 20px;

    font-size: 14px;

    font-weight: bold;
}

.difficulty-section select {
    padding: 8px 12px;

    border: 2px solid #ddd;

    border-radius: 8px;

    outline: none;

    cursor: pointer;

    font-weight: bold;
}

.difficulty-section select:focus {
    border-color: #667eea;
}


/* =================================
   SCOREBOARD
   ================================= */

.scoreboard {
    display: flex;

    justify-content: center;

    gap: 15px;

    margin-bottom: 12px;
}

.score-box {
    min-width: 85px;

    padding: 10px;

    background: #f5f5f5;

    border-radius: 12px;

    display: flex;

    flex-direction: column;

    gap: 4px;

    transition:
        transform 0.2s ease,
        background 0.3s ease,
        box-shadow 0.2s ease;
}

.score-box span {
    font-size: 13px;

    font-weight: bold;

    color: #666;
}

.score-box strong {
    font-size: 25px;

    color: #333;
}


/* =================================
   ACTIVE PLAYER SCORE
   ================================= */

.score-box.active-player {
    transform: scale(1.08);

    box-shadow:
        0 0 15px rgba(102, 126, 234, 0.45);

    border: 2px solid #667eea;
}

.score-box.active-player strong {
    color: #667eea;
}


/* =================================
   SCOREBOARD HOVER
   ================================= */

.score-box:hover {
    transform:
        translateY(-4px)
        scale(1.03);

    box-shadow:
        0 8px 18px rgba(0, 0, 0, 0.15);
}


/* =================================
   SCORE POP ANIMATION
   ================================= */

.score-pop {
    animation:
        scorePop 0.5s ease;
}

@keyframes scorePop {

    0% {
        transform: scale(1);

        text-shadow:
            0 0 0 transparent;
    }

    50% {
        transform: scale(1.4);

        text-shadow:
            0 0 10px rgba(102, 126, 234, 0.8);
    }

    100% {
        transform: scale(1);

        text-shadow:
            0 0 0 transparent;
    }

}


/* =================================
   STATUS TEXT
   ================================= */

#statusText {
    margin: 8px 0;

    font-size: 20px;

    color: #444;

    min-height: 25px;

    transition:
        color 0.3s ease,
        transform 0.3s ease;
}


/* =================================
   TURN TEXT ANIMATION
   ================================= */

#statusText.turn-change {
    animation:
        turnChange 0.4s ease;
}

@keyframes turnChange {

    0% {
        opacity: 0;

        transform:
            translateY(-8px);
    }

    100% {
        opacity: 1;

        transform:
            translateY(0);
    }

}


/* =================================
   BOARD
   ================================= */

.board {
    display: grid;

    grid-template-columns:
        repeat(3, 1fr);

    gap: 12px;

    width: 100%;

    max-width: 400px;

    margin: 20px auto;

    position: relative;
}


/* =================================
   CELLS
   ================================= */

.cell {
    aspect-ratio: 1 / 1;

    background: #f4f4f4;

    border-radius: 15px;

    display: flex;

    justify-content: center;

    align-items: center;

    font-size: 50px;

    font-weight: bold;

    cursor: pointer;

    user-select: none;

    position: relative;

    overflow: hidden;

    transition:
        transform 0.2s ease,
        background 0.3s ease,
        box-shadow 0.3s ease;
}

.cell:hover {
    transform:
        translateY(-3px)
        scale(1.03);

    box-shadow:
        0 8px 18px rgba(0, 0, 0, 0.15);
}

.cell:active {
    transform: scale(0.95);
}


/* =================================
   CELL RIPPLE
   ================================= */

.cell::after {
    content: "";

    position: absolute;

    width: 10px;
    height: 10px;

    background:
        rgba(255, 255, 255, 0.6);

    border-radius: 50%;

    transform: scale(0);

    pointer-events: none;
}

.cell.ripple::after {
    animation:
        rippleEffect 0.5s ease-out;
}

@keyframes rippleEffect {

    0% {
        transform: scale(0);

        opacity: 1;
    }

    100% {
        transform: scale(25);

        opacity: 0;
    }

}


/* =================================
   X MARK
   ================================= */

.cell.x-mark {
    color: #2563eb;

    animation:
        markAppear 0.3s ease;
}


/* =================================
   O MARK
   ================================= */

.cell.o-mark {
    color: #ef4444;

    animation:
        markAppear 0.3s ease;
}


@keyframes markAppear {

    0% {
        transform: scale(0);
    }

    70% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }

}


/* =================================
   WINNING CELL ANIMATION
   ================================= */

.cell.win {
    animation:
        winCell 0.6s ease-in-out infinite alternate;
}

@keyframes winCell {

    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.08);
    }

}


/* =================================
   WINNER
   ================================= */

.cell.winner {
    background: #ffe600;

    animation:
        winnerPulse 0.7s ease-in-out infinite alternate,
        winnerGlow 1.4s ease-in-out infinite;

    z-index: 2;
}

@keyframes winnerPulse {

    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.08);
    }

}

@keyframes winnerGlow {

    0% {
        box-shadow:
            0 0 5px rgba(255, 215, 0, 0.4);
    }

    50% {
        box-shadow:
            0 0 25px rgba(255, 215, 0, 0.9);
    }

    100% {
        box-shadow:
            0 0 5px rgba(255, 215, 0, 0.4);
    }

}


/* =================================
   WINNING LINE
   ================================= */

.winning-line {
    position: absolute;

    height: 6px;

    width: 0;

    background: #ffd700;

    border-radius: 10px;

    left: 50%;

    top: 50%;

    transform:
        translate(-50%, -50%);

    z-index: 10;

    box-shadow:
        0 0 10px rgba(255, 215, 0, 0.8);

    transition:
        width 0.5s ease;
}

.winning-line.show {
    width: 100%;
}


/* =================================
   DRAW ANIMATION
   ================================= */

.board.draw-animation {
    animation:
        drawShake 0.6s ease-in-out;
}

@keyframes drawShake {

    0% {
        transform:
            translateX(0)
            scale(1);
    }

    20% {
        transform:
            translateX(-8px)
            scale(1.02);
    }

    40% {
        transform:
            translateX(8px)
            scale(1.03);
    }

    60% {
        transform:
            translateX(-6px)
            scale(1.02);
    }

    80% {
        transform:
            translateX(6px)
            scale(1.01);
    }

    100% {
        transform:
            translateX(0)
            scale(1);
    }

}


/* =================================
   GAME BUTTONS
   ================================= */

.game-buttons {
    display: flex;

    justify-content: center;

    gap: 12px;

    margin-top: 20px;
}

.game-buttons button {
    padding: 12px 18px;

    border: none;

    border-radius: 10px;

    background: #667eea;

    color: white;

    font-size: 14px;

    font-weight: bold;

    cursor: pointer;

    transition:
        transform 0.2s ease,
        background 0.3s ease;
}

.game-buttons button:hover {
    transform: translateY(-2px);

    background: #5568d9;
}

.game-buttons button:active {
    transform: scale(0.96);
}


/* =================================
   THEME BUTTON
   ================================= */

#themeToggle {
    position: fixed;

    top: 20px;

    right: 20px;

    padding: 10px 16px;

    border: none;

    border-radius: 10px;

    background: white;

    color: #333;

    font-size: 14px;

    font-weight: bold;

    cursor: pointer;

    z-index: 1000;

    box-shadow:
        0 5px 15px rgba(0, 0, 0, 0.15);

    transition:
        transform 0.2s ease,
        background 0.3s ease,
        color 0.3s ease;
}

#themeToggle:hover {
    transform: translateY(-2px);
}


/* =================================
   GAME OVER POPUP
   ================================= */

.game-over {
    position: fixed;

    inset: 0;

    display: none;

    justify-content: center;

    align-items: center;

    background:
        rgba(0, 0, 0, 0.65);

    z-index: 999;
}

.game-over.show {
    display: flex;
}


/* =================================
   GAME OVER BOX
   ================================= */

.game-over-box {
    width: 90%;

    max-width: 380px;

    padding: 30px;

    background: white;

    border-radius: 20px;

    text-align: center;

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.3);

    animation:
        popupAppear 0.4s ease;
}

.game-over-box h2 {
    margin-bottom: 10px;

    font-size: 28px;

    color: #333;
}

.game-over-box p {
    margin-bottom: 20px;

    color: #666;

    font-size: 16px;
}

.game-over-box button {
    padding: 12px 22px;

    border: none;

    border-radius: 10px;

    background: #667eea;

    color: white;

    font-size: 15px;

    font-weight: bold;

    cursor: pointer;

    transition:
        transform 0.2s ease,
        background 0.3s ease;
}

.game-over-box button:hover {
    transform: translateY(-2px);

    background: #5568d9;
}


/* =================================
   NORMAL POPUP ANIMATION
   ================================= */

@keyframes popupAppear {

    0% {
        opacity: 0;

        transform:
            scale(0.7)
            translateY(20px);
    }

    100% {
        opacity: 1;

        transform:
            scale(1)
            translateY(0);
    }

}


/* =================================
   DRAW POPUP ANIMATION
   ================================= */

.game-over.draw-popup .game-over-box {
    animation:
        drawPopup 0.7s ease-out;
}

@keyframes drawPopup {

    0% {
        opacity: 0;

        transform:
            scale(0.5)
            rotate(-5deg);
    }

    60% {
        opacity: 1;

        transform:
            scale(1.08)
            rotate(2deg);
    }

    80% {
        transform:
            scale(0.97)
            rotate(-1deg);
    }

    100% {
        opacity: 1;

        transform:
            scale(1)
            rotate(0);
    }

}


/* =================================
   CONFETTI
   ================================= */

#confetti-container {
    position: fixed;

    inset: 0;

    pointer-events: none;

    overflow: hidden;

    z-index: 2000;
}

.confetti {
    position: absolute;

    width: 10px;

    height: 10px;

    top: -20px;

    animation:
        confettiFall 3s linear forwards;
}

@keyframes confettiFall {

    0% {
        transform:
            translateY(0)
            rotate(0deg);

        opacity: 1;
    }

    100% {
        transform:
            translateY(110vh)
            rotate(720deg);

        opacity: 0;
    }

}


/* =================================
   DARK MODE
   ================================= */

body.dark-mode {
    background:
        linear-gradient(
            135deg,
            #141e30,
            #243b55
        );
}

body.dark-mode .game-container {
    background: #1f2937;

    color: white;

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.45);
}

body.dark-mode h1 {
    color: white;
}

body.dark-mode #statusText {
    color: #f3f4f6;
}

body.dark-mode .player-box label {
    color: #d1d5db;
}

body.dark-mode .player-box input {
    background: #374151;

    color: white;

    border-color: #4b5563;
}

body.dark-mode .difficulty-section {
    color: #f3f4f6;
}

body.dark-mode .difficulty-section select {
    background: #374151;

    color: white;

    border-color: #4b5563;
}

body.dark-mode .score-box {
    background: #374151;
}

body.dark-mode .score-box span {
    color: #d1d5db;
}

body.dark-mode .score-box strong {
    color: white;
}

body.dark-mode .cell {
    background: #374151;

    color: white;
}

body.dark-mode .mode-section button {
    background: #374151;

    color: #f3f4f6;
}

body.dark-mode .mode-section button.active {
    background: #667eea;

    color: white;
}

body.dark-mode #themeToggle {
    background: #374151;

    color: white;
}

body.dark-mode .game-over-box {
    background: #1f2937;

    color: white;
}

body.dark-mode .game-over-box h2 {
    color: white;
}

body.dark-mode .game-over-box p {
    color: #d1d5db;
}


/* =================================
   RESPONSIVE DESIGN
   ================================= */

@media (max-width: 600px) {

    body {
        padding: 20px 10px;
    }

    .game-container {
        padding: 25px 15px;
    }

    h1 {
        font-size: 30px;
    }

    .players {
        flex-direction: column;

        gap: 12px;
    }

    .mode-section {
        flex-direction: column;
    }

    .scoreboard {
        gap: 8px;
    }

    .score-box {
        min-width: 70px;
    }

    .cell {
        font-size: 40px;

        border-radius: 12px;
    }

    #themeToggle {
        top: 10px;

        right: 10px;

        padding: 8px 11px;

        font-size: 12px;
    }

    .game-buttons {
        flex-direction: column;
    }

    .game-buttons button {
        width: 100%;
    }

}


/* =================================
   SMALL MOBILE
   ================================= */

@media (max-width: 380px) {

    .game-container {
        padding: 20px 10px;
    }

    h1 {
        font-size: 26px;
    }

    .cell {
        font-size: 32px;
    }

    .score-box {
        min-width: 60px;

        padding: 8px 5px;
    }

    .score-box strong {
        font-size: 21px;
    }

}


/* =================================
   NEW ROUND ANIMATION
   ================================= */

@keyframes newRoundIn {

    0% {
        opacity: 0;

        transform:
            scale(0.9);
    }

    100% {
        opacity: 1;

        transform:
            scale(1);
    }

}

.board.new-round-animation {
    animation:
        newRoundIn 0.4s ease;
}


/* =================================
   WINNER SCORE HIGHLIGHT
   ================================= */

.score-box.score-winner {
    animation:
        winnerScore 0.7s ease;
}

@keyframes winnerScore {

    0% {
        transform: scale(1);

        box-shadow:
            0 0 0 rgba(255, 215, 0, 0);
    }

    50% {
        transform: scale(1.15);

        box-shadow:
            0 0 25px rgba(255, 215, 0, 0.8);
    }

    100% {
        transform: scale(1);

        box-shadow:
            0 0 0 rgba(255, 215, 0, 0);
    }

}


/* =================================
   DRAW SCORE HIGHLIGHT
   ================================= */

.score-box.score-draw {
    animation:
        drawScoreHighlight 0.7s ease;
}

@keyframes drawScoreHighlight {

    0% {
        transform: scale(1);

        box-shadow:
            0 0 0 rgba(102, 126, 234, 0);
    }

    50% {
        transform: scale(1.15);

        box-shadow:
            0 0 25px rgba(102, 126, 234, 0.8);
    }

    100% {
        transform: scale(1);

        box-shadow:
            0 0 0 rgba(102, 126, 234, 0);
    }

}
















